from django.db import models
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.models import CoreModel, SoftDeleteModel
from dvadmin.utils.viewset import CustomModelViewSet

# drf专用过滤器模块
from django_filters import rest_framework as filters


class Pbom(CoreModel):

    shun_xu_hao = models.TextField(verbose_name="顺序号", blank=True, null=True)
    IA = models.TextField(verbose_name="IA", blank=True, null=True)
    IA_ying_wen_ming_cheng = models.TextField(verbose_name="IA英文名称", blank=True, null=True)
    IA_zhong_wen_ming_cheng = models.TextField(verbose_name="IA中文名称", blank=True, null=True)
    ji_bie = models.TextField(verbose_name="级别", blank=True, null=True)
    ling_bu_jian_hao = models.TextField(verbose_name="零部件号", blank=True, null=True)
    ling_bu_jian_zhong_wen_ming_cheng = models.TextField(verbose_name="零部件中文名称", blank=True, null=True)
    ling_bu_jian_ying_wen_ming_cheng = models.TextField(verbose_name="零部件英文名称", blank=True, null=True)
    dan_wei_yong_liang = models.TextField(verbose_name="单位用量", blank=True, null=True)
    mo_kuai = models.TextField(verbose_name="模块", blank=True, null=True)
    mo_kuai_zhong_wen_miao_shu = models.TextField(verbose_name="模块中文描述", blank=True, null=True)
    ben_se_jian_biao_shi = models.TextField(verbose_name="本色件标识", blank=True, null=True)
    yan_se_jian_biao_shi = models.TextField(verbose_name="颜色件标识", blank=True, null=True)
    bian_liang_tiao_jian = models.TextField(verbose_name="变量条件", blank=True, null=True)
    VPPS = models.TextField(verbose_name="VPPS", blank=True, null=True)
    VPPS_ying_wen_ming_cheng = models.TextField(verbose_name="VPPS英文名称", blank=True, null=True)
    VPPS_zhong_wen_ming_cheng = models.TextField(verbose_name="VPPS中文名称", blank=True, null=True)
    FNA = models.TextField(verbose_name="FNA", blank=True, null=True)
    FNA_zhong_wen_miao_shu = models.TextField(verbose_name="FNA中文描述", blank=True, null=True)
    FNA_ying_wen_miao_shu = models.TextField(verbose_name="FNA英文描述", blank=True, null=True)
    fu_ji = models.TextField(verbose_name="父级", blank=True, null=True)
    num_00_ji = models.TextField(verbose_name="00级", blank=True, null=True)
    pai_xu_zi_fu_chuan = models.TextField(verbose_name="排序字符串", blank=True, null=True)
    jin_gu_li_ju = models.TextField(verbose_name="紧固力矩", blank=True, null=True)
    guan_jian_li_ju = models.TextField(verbose_name="关键力矩", blank=True, null=True)
    huo_yuan = models.TextField(verbose_name="货源", blank=True, null=True)
    huo_yuan_miao_shu = models.TextField(verbose_name="货源描述", blank=True, null=True)
    jie_gou_huo_yuan = models.TextField(verbose_name="结构货源", blank=True, null=True)
    jie_gou_huo_yuan_miao_shu = models.TextField(verbose_name="结构货源描述", blank=True, null=True)
    cai_gou_dan_yuan_biao_shi = models.TextField(verbose_name="采购单元标识", blank=True, null=True)
    shou_hou_jian_biao_shi = models.TextField(verbose_name="售后件标识", blank=True, null=True)
    shou_yong_che_xing = models.TextField(verbose_name="首用车型", blank=True, null=True)
    ling_jian_zhuang_tai = models.TextField(verbose_name="零件状态", blank=True, null=True)
    du_liang_dan_wei = models.TextField(verbose_name="度量单位", blank=True, null=True)
    ling_jian_zhi_liang_kg_dan_wei = models.TextField(verbose_name="零件质量kg/单位", blank=True, null=True)
    station = models.TextField(verbose_name="工位", blank=True, null=True)
    cai_liao = models.TextField(verbose_name="材料", blank=True, null=True)
    liao_hou_mm = models.TextField(verbose_name="料厚mm", blank=True, null=True)
    dui_cheng_jian_biao_shi = models.TextField(verbose_name="对称件标识", blank=True, null=True)
    dui_cheng_jian_hao = models.TextField(verbose_name="对称件号", blank=True, null=True)
    ling_jian_lei_xing = models.TextField(verbose_name="零件类型", blank=True, null=True)
    ling_jian_zhong_yao_du = models.TextField(verbose_name="零件重要度", blank=True, null=True)
    fa_gui_jian_biao_shi = models.TextField(verbose_name="法规件标识 ", blank=True, null=True)
    guan_jian_zhi_liang_te_xing = models.TextField(verbose_name="关键质量特性 ", blank=True, null=True)
    ruan_jian_ban_ben = models.TextField(verbose_name="软件版本", blank=True, null=True)
    ying_jian_ban_ben = models.TextField(verbose_name="硬件版本", blank=True, null=True)
    shu_mo_bian_hao = models.TextField(verbose_name="数模编号", blank=True, null=True)
    shu_mo_ban_ben = models.TextField(verbose_name="数模版本", blank=True, null=True)
    shu_mo_fa_bu_shi_jian = models.TextField(verbose_name="数模发布时间", blank=True, null=True)
    tu_zhi_hao = models.TextField(verbose_name="图纸号 ", blank=True, null=True)
    tu_zhi_ban_ben = models.TextField(verbose_name="图纸版本", blank=True, null=True)
    tu_zhi_fa_bu_shi_jian = models.TextField(verbose_name="图纸发布时间", blank=True, null=True)
    SOR_bian_hao = models.TextField(verbose_name="SOR编号", blank=True, null=True)
    SOR_fa_bu_shi_jian = models.TextField(verbose_name="SOR发布时间", blank=True, null=True)
    ESO_bian_hao = models.TextField(verbose_name="ESO编号", blank=True, null=True)
    ESO_pi_zhun_shi_jian = models.TextField(verbose_name="ESO批准时间", blank=True, null=True)
    ling_bu_jian_you_xiao_xing = models.TextField(verbose_name="零部件有效性", blank=True, null=True)
    ze_ren_gong_cheng_shi = models.TextField(verbose_name="责任工程师", blank=True, null=True)
    ze_ren_gong_cheng_shi_gong_hao = models.TextField(verbose_name="责任工程师工号", blank=True, null=True)
    ze_ren_zhuan_ye = models.TextField(verbose_name="责任专业", blank=True, null=True)
    bei_zhu = models.TextField(verbose_name="备注", blank=True, null=True)
    PCN = models.TextField(verbose_name="PCN", blank=True, null=True)
    PCN_sheng_xiao_ri_qi = models.TextField(verbose_name="PCN生效日期", blank=True, null=True)
    ET = models.TextField(verbose_name="ET", blank=True, null=True)
    sheng_xiao_ri_qi = models.TextField(verbose_name="生效日期", blank=True, null=True)
    shi_xiao_ri_qi = models.TextField(verbose_name="失效日期", blank=True, null=True)
    jian_yi_sheng_xiao_ri_qi = models.TextField(verbose_name="建议生效日期", blank=True, null=True)
    jian_yi_shi_xiao_ri_qi = models.TextField(verbose_name="建议失效日期", blank=True, null=True)
    C62XLV2 = models.TextField(verbose_name="C62X-LV2", blank=True, null=True)
    C62XLV3 = models.TextField(verbose_name="C62X-LV3", blank=True, null=True)
    C62XLV4 = models.TextField(verbose_name="C62X-LV4", blank=True, null=True)
    C62XLV1MT = models.TextField(verbose_name="C62X-LV1 MT", blank=True, null=True)
    C62XLV17DCT = models.TextField(verbose_name="C62X-LV1-7DCT", blank=True, null=True)


    class Meta:
        db_table = 'station_pbom'


class PbomModelSerializer(CustomModelSerializer):    
    class Meta:
        model = Pbom
        fields = '__all__'


class PbomFilter(filters.FilterSet):
    ling_bu_jian_hao = filters.CharFilter(field_name='ling_bu_jian_hao', lookup_expr='icontains')
    ling_bu_jian_zhong_wen_ming_cheng = filters.CharFilter(field_name='ling_bu_jian_zhong_wen_ming_cheng', lookup_expr='icontains')
    ling_bu_jian_ying_wen_ming_cheng= filters.CharFilter(field_name='ling_bu_jian_ying_wen_ming_cheng', lookup_expr='icontains')
    station = filters.CharFilter(field_name='station', lookup_expr='icontains')
    C62XLV2 = filters.CharFilter(field_name='C62XLV2', lookup_expr='icontains')
    C62XLV3 = filters.CharFilter(field_name='C62XLV3', lookup_expr='icontains')
    C62XLV4 = filters.CharFilter(field_name='C62XLV4', lookup_expr='icontains')
    C62XLV1MT = filters.CharFilter(field_name='C62XLV1MT', lookup_expr='icontains')
    C62XLV17DCT = filters.CharFilter(field_name='C62XLV17DCT', lookup_expr='icontains')
    class Meta:
        models = Pbom
        fields = '__all__'


class PbomViewSet(CustomModelViewSet):
    # FIXME: 把extra_filter_class = []放到这里，避免更新数据时权限不够错误
    # extra_filter_class = []
    # permission_classes = []
    values_queryset = Pbom.objects.all()
    serializer_class = PbomModelSerializer
    filter_class = PbomFilter


